/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ru.ssau;

import ru.ssau.server.Server;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import org.jdom.Element;
import ru.ssau.entities.AuthorizationInfo;
import ru.ssau.entities.Message;
import ru.ssau.entities.Thread;
import ru.ssau.entities.User;
import ru.ssau.model.DataModel;
import ru.ssau.server.InfoMessageListener;
import ru.ssau.utils.XMLHelper;

/**
 *
 * @author Дима
 */
public class Main {
    public static void main(String[] args) {
        try {
            //Порт указывается как параметр командной строки
            int port;
            if(args.length == 0) port = 8189; //8189 - порт по умолчанию
            else port = Integer.parseInt(args[1]);
            Server s = new Server(new DataModel());
            s.addInfoMessageListener(new InfoMessageListener() {
                public void receiveInfoMessage(String infoMessage) {
                    System.out.println(infoMessage);
                }
            });
            s.startServer(port);
        } catch(IOException ex) {
            ex.printStackTrace();
        }
        //тестовое заполнение модели
        /*DataModel model=new DataModel();
        Thread thread=new Thread(1,"ThreadCaption");
        model.addThread(thread);
        Thread thread2=new Thread(2, "AnotherThreadCaption");
        model.addThread(thread2);
        AuthorizationInfo info=new AuthorizationInfo("MyLogin", "MyPass");
        User user=new User(1,"UserName",new Date(1999,10,12),"SomeInfo",info);
        model.addUser(user);
        Message msg=new Message(1, "MsgCaption", "SomeText", 1, 1, new Date(1900, 2, 3));
        model.addMessage(msg);
        Element modelElem=model.toXMLElement();
        DataModel model2=new DataModel();
        model2.loadFromXMLElement(modelElem);
        System.out.println(model2.getThreadById(2));*/
    }

}
